﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

public class GameObjectTools
{
    public static GameObject Find(string path, GameObject parent)
    {
        string[] strings = path.Split(new char[] { '/' });
        GameObject go = parent;
        for (int i = 0; i < strings.Length; i++)
        {
            go = go.transform.Find(strings[i])?.gameObject;
            if (go == null) break;
        }
        return go;
    }
    public static T Find<T>(string path, GameObject parent)where T : Component
    {
        GameObject go=Find(path, parent);
        T t=go.GetComponent<T>();
        if(t == null) t=go.AddComponent<T>();
        return t;
    }
}